package com.ruoyi.web.controller.market.sys;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.ApkInfo;
import com.ruoyi.sys.service.IApkInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.ApkInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 马甲包管理Controller
 * 
 * @author ruoyi
 * @date 2022-08-23
 */
@Controller
@RequestMapping("/sys/apk")
public class ApkInfoController extends BaseController
{
    private String prefix = "sys/apk";

    @Autowired
    private IApkInfoService apkInfoService;

    @RequiresPermissions("sys:apk:view")
    @GetMapping()
    public String apk()
    {
        return prefix + "/apk";
    }

    /**
     * 查询马甲包管理列表
     */
    @RequiresPermissions("sys:apk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ApkInfo apkInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = apkInfoService.selectApkInfoListMap(apkInfo);
        mapList = new ApkInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出马甲包管理列表
     */
    @RequiresPermissions("sys:apk:export")
    @Log(title = "马甲包管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ApkInfo apkInfo)
    {
        List<ApkInfo> list = apkInfoService.selectApkInfoList(apkInfo);
        ExcelUtil<ApkInfo> util = new ExcelUtil<ApkInfo>(ApkInfo.class);
        return util.exportExcel(list, "马甲包管理数据");
    }

    /**
     * 新增马甲包管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存马甲包管理
     */
    @RequiresPermissions("sys:apk:add")
    @Log(title = "马甲包管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ApkInfo apkInfo)
    {
        return toAjax(apkInfoService.insertApkInfo(apkInfo));
    }

    /**
     * 修改马甲包管理
     */
    @RequiresPermissions("sys:apk:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ApkInfo apkInfo = apkInfoService.selectApkInfoById(id);
        mmap.put("apkInfo", apkInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存马甲包管理
     */
    @RequiresPermissions("sys:apk:edit")
    @Log(title = "马甲包管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ApkInfo apkInfo)
    {
        return toAjax(apkInfoService.updateApkInfo(apkInfo));
    }

    /**
     * 删除马甲包管理
     */
    @RequiresPermissions("sys:apk:remove")
    @Log(title = "马甲包管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(apkInfoService.deleteApkInfoByIds(ids));
    }
}
